var removeElements = function (head, val) {
  let dummy = new ListNode(0);
  dummy.next = head;
  let pre = dummy,
      cur = head;
  while (cur !== null) {
    if (cur.val == val) {
      pre.next = cur.next;
      cur = pre.next;
    } else {
      pre = cur;
      cur = cur.next;
    }
  }
  return dummy.next;
}